package yxk.wtc.wtom.business;

import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.plugin.AbstractMobFormPlugin;
import kd.bos.orm.query.QFilter;
import kd.hr.hbp.business.servicehelper.HRBaseServiceHelper;
import kd.wtc.wtabm.common.vaapply.VaApplyMobConstants;
import kd.wtc.wtbs.common.constants.WTCCommonConstants;
import kd.wtc.wtbs.wtabm.common.constants.VaApplyConstants;

import java.util.EventObject;


/**
 * 休假变更申请插件扩展
 */
public class VaUpdateMobChangeExtPlugin extends AbstractMobFormPlugin implements VaApplyMobConstants, VaApplyConstants {


    @Override
    public void afterBindData(EventObject evt) {
        super.afterBindData(evt);
        OperationStatus status = getView().getFormShowParameter().getStatus();
        if (status.equals(OperationStatus.ADDNEW)) {
            Long parentId = getView().getFormShowParameter().getCustomParam(PK_CHANGEID);
            if (parentId != null) {
                supplementModel(parentId);
            }
        }
    }

    /**
     * 补充拷贝原单信息
     *
     * @param parentId 父单据ID
     */
    private void supplementModel(Long parentId) {
        HRBaseServiceHelper serviceHelper = new HRBaseServiceHelper(PAGE_WTABM_VAAPPLY);
        DynamicObject parentDynObj = serviceHelper.queryOne("org.id", new QFilter(WTCCommonConstants.ID, QFilter.equals, parentId));
        this.getModel().setValue(WTCCommonConstants.ORG, parentDynObj.getLong("org.id"));
    }
}